import axios from "axios";
import { showToast } from 'vant';

import router from "../router";

const request = axios.create({
  // baseURL:'http://120.46.204.16/haigou/api/'
  baseURL: '/api'
})

// 在请求头添加token
request.interceptors.request.use((config) => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers["token"] = token;
  }
  // console.log(config);
  return config;
});

// 响应拦截
request.interceptors.response.use((response) => {
  if (response.data.code !== '200') {
    if (response.data.code === 10119) {
      // showToast('提示内容');
      router.push('/login')
    }
    showToast(response.data.message);
  }
  return response
})

export default request
